<?php 
@session_start();
require_once('../config/config.php');
require_once('../utils/CommonUtils.php');
require_once('../utils/DBUtils.php');
include ("../utils/Constants.php");
require_once('../utils/BaseDAO.php');
require("../utils/Session.php");
require_once('../utils/Pager.php');

$userid = Session::get('userid');

$commonUtils = new CommonUtils();
$pager = new Pager();

$page = $commonUtils->getParameter("p", 1);
$sortExpression = $commonUtils->getParameter("s", "ct.createddate");
$sortDirection = $commonUtils->getParameter("d", "desc");

$contentId = $commonUtils->getParameter("id", 0);
$baseDAO = new BaseDAO();
$contents = $baseDAO->getContents(array("id", "image", "title", "brief", "content", "createdby", "createddate", "views"), "", "order by createddate desc", ($page - 1) * $contentWebPageSize, $contentWebPageSize);
$totalItems = $baseDAO->getTotalItems("content", "1");
$mostviews = $baseDAO->getItems("content", array("id", "title", "createddate", "views"), "status = 1", "order by views desc", 0, 10);
?>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<LINK REL="SHORTCUT ICON" HREF="../img/fm.ico"> 
		<title>Nguyễn Đậu - Bài viết</title>
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<link rel="stylesheet" type="text/css" href="../css/jquery.alert.css"/>
		<link rel="stylesheet" type="text/css" href="../css/jquery.fancybox.css"/>
		<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="../js/jquery.hind.js"></script>
		<script type="text/javascript" src="../js/jquery.fancybox.js"></script>
		<script type="text/javascript" src="../js/jquery.corner.js"></script>
		<script src="../js/jquery.alerts.js"></script>
		<link href="../css/bootstrap.css" rel="stylesheet">
		<script src="../js/bootstrap.min.js"></script>
	</head>
	<body>
		<div id="content">
			<?php include '../include/webheader.php';?>
			<div id="floating-box"></div>
			<div id="page">
				<div class="twocol_col1">
					<?php foreach ($contents as $content){ ?>
							<div class="hostpost" style="width:100%;">
								<div id="img"><img src="<?php echo '../images/content/thumb/'.$content['image'];?>" width="120px"/></div>
								<div id="detail" style="width:520px">
									<div id="title" class="title"><a href="<?php echo './chi-tiet.php?id='.$content['id'];?>"><?php echo $content['title'];?></a></div>
									<div id="brief"><?php echo $content['brief'];?></div>
									<div id="author">
										<span class="createdby"><?php echo $content['createdby'];?></span>
										<span class="displayDate"><?php echo $commonUtils->timePost($content['createddate']);?></span>
									</div>
								</div>
							</div>
						<?php }?>
						<div class="pager">
							<span id="total"><?php $pager->drawResults($totalItems);?></span>
							<span id="pager"><?php $pager->drawPager($totalItems, $contentWebPageSize, $page);?></span>
							<div style="clear:both"></div>
						</div>
				</div>
				<div class="twocol_col2">
					<div data-spy="affix" data-offset-top="10" style="border-left: 1px solid #CCCCCC;width:266px;">
						<div class="relateItems">
							<p style="font-weight:bold">Xem nhiều:</p>
							<?php foreach($mostviews as $item){?>
								<div>[<?php echo ($item['views'] > 9 ? $item['views']: ' '.$item['views']);?>]&nbsp;<a href="./chi-tiet.php?id=<?php echo $item["id"];?>"><?php echo $item["title"];?></a>&nbsp;<span><?php echo $commonUtils->formatDate($item["createddate"], "d/m/Y")?></span></div>
							<?php }?>
						</div>
					</div>
				</div>
				<div style="clear:both"></div>
			</div>
			<?php include '../include/webfooter.php';?>
		</div>
		<script type="text/javascript">
			$(function(){
				$('.myCorner').corner();
				$(".hostpost").hover(function(){
					$(this).addClass("hostpost_");
				}, function(){
					$(this).removeClass("hostpost_");
				});
			});
		</script>
	</body>
</html>
